package
{
	import com.oosterwijk.irc.User;
	
	import flash.events.MouseEvent;
	import flash.text.StyleSheet;
	import flash.text.TextFieldAutoSize;
	
	import qnx.ui.buttons.*;
	import qnx.ui.core.*;
	import qnx.ui.data.DataProvider;
	import qnx.ui.events.ListEvent;
	import qnx.ui.events.ScrollEvent;
	import qnx.ui.listClasses.List;
	import qnx.ui.listClasses.ListSelectionMode;
	import qnx.ui.listClasses.ScrollDirection;
	import qnx.ui.listClasses.ScrollPane;
	import qnx.ui.text.Label;

	public class ChannelView extends BaseView
	{
		private var _txtScrlr:ScrollPane;
		private var _statusText:Label;
		private var _chList:List;
		public function ChannelView()
		{
			super();
			configUI();
			for(var i:int = 0;i<20;i++){
				_chList.dataProvider.addItem(new User("@","user "+i));
			}
		}
		
		private function configUI():void
		{
			var mainContainer:Container = new Container();
			//mainContainer.margins = Vector.<Number>([2,2,2,2]);
			mainContainer.flow = ContainerFlow.HORIZONTAL;
			//mainContainer.debugColor = 0xFFCC00;
			this.addChild(mainContainer);
			
			// create subcontainer on left side of the screen 
			var mySub:Container = new Container();
			//mySub.margins = Vector.<Number>([2,2,2,2]);            
			mySub.flow = ContainerFlow.VERTICAL;
			//mySub.debugColor = 0xFF3300;
			mySub.padding = 10;
			mySub.size = 80;
			mySub.sizeUnit = SizeUnit.PERCENT;
			mySub.align = ContainerAlign.NEAR;
			
			_txtScrlr = new ScrollPane();
			//scrlr.setPosition(0, 0);
			_txtScrlr.size = 100;

			_txtScrlr.sizeUnit = SizeUnit.PERCENT;
			_txtScrlr.scrollDirection = ScrollDirection.VERTICAL;
			
			var css:StyleSheet = new StyleSheet();
			css.setStyle("body", {fontFamily:'Courier New', fontSize:'18'});
			
			
			_statusText = new Label();
			_statusText.autoSize = TextFieldAutoSize.LEFT;
			_statusText.multiline = true;
			_statusText.textField.wordWrap = true;
			_statusText.width = 816;
			_statusText.textField.styleSheet = css;
			_statusText.htmlText = "<body>";
			//statusText.height = 470;
			_txtScrlr.setScrollContent(_statusText);
			
			mySub.addChild(_txtScrlr);
			
			// create subcontainer on left side of the screen 
			var mySubRight:Container = new Container();
			//mySubRight.margins = Vector.<Number>([2,2,2,2]);            
			mySubRight.flow = ContainerFlow.VERTICAL;
			//mySubRight.debugColor = 0xFF3300;
			mySubRight.padding = 10;
			mySubRight.size = 20;
			mySubRight.sizeUnit = SizeUnit.PERCENT;			
			mySubRight.align = ContainerAlign.MID;
			
			_chList = new List();                       
			_chList.width = 200;
			_chList.height = 460;
			_chList.columnWidth = 200;
			_chList.setSkin(UserListRenderer);
			
			//set the dataProvider
			_chList.allowDeselect = false;
			_chList.selectionMode = ListSelectionMode.SINGLE;
			_chList.scrollDirection = ScrollDirection.VERTICAL;
			//_chList.dataProvider = new DataProvider(_chArray);
			//_chList.addEventListener(ListEvent.ITEM_CLICKED, onListClick);
			mySubRight.addChild(_chList);
			
			mainContainer.addChild(mySub);
			mainContainer.addChild(mySubRight);
			
			mainContainer.setSize(1024, 460);
			
			var bt:LabelButton = new LabelButton();
			bt.label = "Add text";
			bt.addEventListener(MouseEvent.CLICK, btOnclick);
			//this.addChild(bt);
		}
		private function btOnclick(event:MouseEvent):void
		{
			appendHTML("channel view...声明说，就搜集关于本·拉登下落的情报工作，军方“承认存在不足之处”，已经下令展开调查。“与此同时”，军队情报部门在打击“基地”和其他恐怖组织上取得无与伦比的成就<br>");
		}
		public function appendHTML(txt:String):void
		{
			_statusText.htmlText += txt;
			if(_statusText.textHeight > _txtScrlr.height){
				_txtScrlr.scrollY = _statusText.textHeight;
				_txtScrlr.update();
			}
			
		}
	}
}